package club.kingyin.commons.clients;

import club.kingyin.commons.entity.Ids;
import club.kingyin.commons.entity.user.Log;
import club.kingyin.commons.entity.user.Message;
import club.kingyin.commons.entity.user.User;
import club.kingyin.commons.mail.MailMessage;
import club.kingyin.commons.response.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CompletableFuture;

@FeignClient(value = "ky-blog-pro-user")
//@FeignClient(value = "ky-blog-pro-user",url = "http://test2.kingyin.club:8080")
public interface UserClient {

    /**
     * 登录验证
     * @param user 用户
     * @return 登录结果
     */
    @PostMapping(value = "/user/login", headers = {"KY-SERVICE=kingyin is yyds!"})
    Result authentication(@RequestBody User user);

    /**
     * 记录日志
     * @param log 日志信息
     * @return 响应结果
     */
    @Async
    @PostMapping(value = "/log", headers = {"KY-SERVICE=kingyin is yyds!"})
    CompletableFuture<Result> insertAsync(@RequestBody Log log);

    @PostMapping(value = "/log", headers = {"KY-SERVICE=kingyin is yyds!"})
    Result insert(@RequestBody Log log);

    @Async
    @PutMapping(value = "/log", headers = {"KY-SERVICE=kingyin is yyds!"})
    CompletableFuture<Result> updateAsync(@RequestBody Log log);

    @PutMapping(value = "/log", headers = {"KY-SERVICE=kingyin is yyds!"})
    Result update(@RequestBody Log log);

    @PutMapping(value = "/log/append", headers = {"KY-SERVICE=kingyin is yyds!"})
    Result appendResponse(@RequestBody Log log);

    @Async
    @PutMapping(value = "/log/append", headers = {"KY-SERVICE=kingyin is yyds!"})
    CompletableFuture<Result> appendResponseAsync(@RequestBody Log log);

    @Async
    @PostMapping(value = "/message/notice", headers = {"KY-SERVICE=kingyin is yyds!"})
    CompletableFuture<Result> sentMessage(@RequestBody Message message);

    @Async
    @PostMapping(value = "/mail", headers = {"KY-SERVICE=kingyin is yyds!"})
    CompletableFuture<Result> sendMailAsync(@RequestBody MailMessage data);
    
    @PostMapping(value = "/mail", headers = {"KY-SERVICE=kingyin is yyds!"})
    Result sendMail(@RequestBody MailMessage data);

    @PostMapping(value = "/message/delete/failed", headers = {"KY-SERVICE=kingyin is yyds!"})
    Result removeByAsyncFailedIds(@RequestBody Ids ids);

    @GetMapping(value = "/user/titled",headers = {"KY-SERVICE=kingyin is yyds!"})
    Result getTitledById(@RequestParam int id);

    @GetMapping(value = "/log/history/all",headers = {"KY-SERVICE=kingyin is yyds!"})
    Result getHistoryByUserid(@RequestParam int userid);
}
